package com.jxbeidou.gateway.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.util.pattern.PathPatternParser;

/**
 * @program: jxbeidou-basic
 * @ClassName: CoreConfig
 * @description: 跨域请求配置
 * @author: 杜晓祥
 * @create: 2023-12-21 11:24
 * 版权所有：交信北斗(北京)信息科技有些公司
 */
@Configuration
@Slf4j
public class CoreConfig {

    @Bean
    public CorsWebFilter corsFilter() {
        log.debug("跨域请求");
        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedMethod("*");
        config.addAllowedOrigin("*");
        config.addAllowedHeader("*");
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
        source.registerCorsConfiguration("/**", config);

        return new CorsWebFilter(source);
    }

}
